<!DOCTYPE html>
<html>
<head>
    {include file="layout:_meta" /}
</head>
<body>
<div class="layui-fluid" style="padding-top: 20px">
    <div class="layui-card">
        <div class="layui-card-header">系统设置</div>
        <div class="layui-card-body">
            <form class="layui-form" lay-filter="layuiadmin-form-admin" action="{:url('config/system')}">
                <div class="layui-tab layui-tab-brief" >
                    <ul class="layui-tab-title">
                        {foreach $group as $key=>$item }
                            {eq name="key" value="0"}
                                <li class="layui-this">{$item.title}</li>
                            {else/}
                                <li>{$item.title}</li>
                            {/eq}
                        {/foreach}
                    </ul>
                    <div class="layui-tab-content" >
                        {foreach $list as $key=>$item }
                            <div class="layui-tab-item {eq name="key" value="0"} layui-show{/eq} ">
                                {volist name="item.config" id="config"}
                                    <div class="layui-form-item">
                                        <label class="layui-form-label" style="width: 150px">{$config.remark}：</label>
                                        <div class="layui-input-block" style="margin-left: 180px">
                                        {eq name="config.type" value="input"}
                                            <input type="text" name="{$item.name}[{$config.code}]" placeholder="请输入{$config.remark}" autocomplete="off" class="layui-input" value="{$config.value}">
                                        {/eq}
                                        {eq name="config.type" value="radio"}
                                            <input type="radio" name="{$item.name}[{$config.code}]" value="1" title="是"  {eq name="config.value" value="1"}checked{/eq} >
                                            <input type="radio" name="{$item.name}[{$config.code}]" value="0" title="否" {eq name="config.value" value="0"}checked{/eq} >
                                        {/eq}
                                        {eq name="config.type" value="textarea"}
                                            <textarea name="{$item.name}[{$config.code}]" placeholder="请输入{$config.remark}" class="layui-textarea">{$config.value}</textarea>
                                        {/eq}
                                        {eq name="config.type" value="image"}
                                            <input type="hidden" id="image_input" name="{$item.name}[{$config.code}]" value="{$config.value}"  lay-reqtext="{$config.remark}">
                                            <img id="image" width="108px" height="108px"
                                                 {if condition="isset($config.value)&&$config.value!=''" }
                                                 src="{$config.value}"{else /}src="__static__/admin/style/img/upload.png"{/if}
                                            />
                                        {/eq}
                                        </div>
                                    </div>
                                {/volist}
                                <div class="layui-form-item">
                                    <div class="layui-input-block">
                                        <button class="layui-btn" lay-submit lay-filter="submit">确认</button>
                                    </div>
                                </div>
                            </div>
                        {/foreach}
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

{include file="layout:_footer" /}
<script>
    var images = [];
    layui.config({
        base: '__static__/admin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form', 'upload'], function(){
        var form = layui.form,$ = layui.$, upload = layui.upload, layedit  = layui.layedit;

        //头像图片上传
        upload.render({
            elem: '#image'
            ,url: "{:url('upload/image')}?type=system"
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#image').attr('src', result); //图片链接（base64）
                });
            }
            ,done: function(res){
                //如果上传失败
                if(res.code == 0){
                    return layer.msg('上传失败');
                }
                //上传成功
                $('#image_input').val(res.data);
                layer.msg('上传成功');
            }
            ,error: function(){}
        });

        //监听表单提交
        form.on('submit(submit)', function(data){
            layer.confirm('您确认要提交吗？', {
                btn: ['确认','取消'] //按钮
            }, function(index){
                $.post(data.form.action, data.field, function (res) {
                    var icon = 5;
                    if (res.code) {
                        icon = 6;
                    }
                    layer.msg(res.msg, {icon: icon, time: 1500},function () {
                        window.location.reload();
                    });
                }, 'json');
            }, function(){
                layer.msg('已取消..');
                return false;
            });
            return false;
        });

    })
</script>
</body>
</html>